// Ninf-G-XX, ver. 0.1
// Copyright 2011 National Institute of Advanced Industrial Science and Technology
// 
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// 
//     http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef _GRPC_H_
#define _GRPC_H_
#include <sys/types.h>

/**
 * This file define the Data Structures for Grid RPC API.
 *
 */
#include "grpcError.h"

/**
 * The value returned when effective Session ID is not found.
 */
#define GRPC_SESSIONID_VOID               (-1)

/**
 * Status of Session
 */
/* Session is done */
#define GRPC_SESSION_DONE                  1
/* Argument transmission is not completed. */
#define GRPC_SESSION_ARG_IS_NOT_TRANSMITED 2
/* Session is running */
#define GRPC_SESSION_EXECUTING             3
/* Session is not running */
#define GRPC_SESSION_DOWN                  4
/* API was failed */
#define GRPC_SESSION_UNKNOWN_STATUS        5

/**
 * Represent a specific non-blocking GridRPC call
 */
typedef int grpc_sessionid_t;

/**
 * Information for all error and status codes
 */
typedef int grpc_error_t;

/**
 * Function handle
 */

/**
 * Prototype declaration of GRPC APIs
 */

#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */

typedef struct grpc_func_handle_s {
		char * server_name;
		char * entry_name;
} grpc_function_handle_t;


/* Initializing/Finalizing API */
grpc_error_t grpc_initialize(const char *);
grpc_error_t grpc_finalize(void);

/* Function handle management API */
grpc_error_t grpc_function_handle_init(
    grpc_function_handle_t *, const char *, const char *);
grpc_error_t grpc_function_handle_default(grpc_function_handle_t *, const char *);
grpc_error_t grpc_function_handle_destruct(grpc_function_handle_t *);


/* GridRPC call API */
grpc_error_t grpc_call(grpc_function_handle_t *, ...);
grpc_error_t grpc_call_async(grpc_function_handle_t *, grpc_sessionid_t *, ...);

/* Asynchronous GridRPC wait API */
grpc_error_t grpc_wait(grpc_sessionid_t);
grpc_error_t grpc_wait_all(void);
grpc_error_t grpc_wait_any(grpc_sessionid_t *);
grpc_error_t grpc_wait_and(grpc_sessionid_t *, size_t);
grpc_error_t grpc_wait_or(grpc_sessionid_t *, size_t, grpc_sessionid_t *);

/* Asynchronous GridRPC control API */
grpc_error_t grpc_cancel(grpc_sessionid_t);
grpc_error_t grpc_cancel_all(void);
grpc_error_t grpc_probe(grpc_sessionid_t);
grpc_error_t grpc_probe_or(grpc_sessionid_t *, size_t, grpc_sessionid_t *);

/* Error Reporting API */
const char * grpc_error_string(grpc_error_t);
grpc_error_t grpc_get_failed_sessionid(grpc_sessionid_t *);

#ifdef __cplusplus
}
#endif /* __cplusplus */

#include "grpcError.h"
#endif /* _GRPC_H_ */

